package com.woniuxy.test_collections;

/**
 * description: TestCollections <br>
 * date: 2022/2/4 4:34 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Collections辅助类的使用
 */
public class TestCollections {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("猪" + i);
        }
        System.out.println(list);

        Collections.shuffle(list);//随机排列list
        System.out.println(list);

        Collections.reverse(list);//逆序排序
        System.out.println(list);

        Collections.sort(list); //按照递增的方法排序,自定义类要是使用:Comparable接口
        System.out.println(list);

        System.out.println(Collections.binarySearch(list, "长")); //使用二分法查找
    }
}
